package com.zhang.controller;

import com.github.pagehelper.PageInfo;
import com.zhang.domain.Department;
import com.zhang.domain.DepartmentVO;
import com.zhang.domain.orderAddress;
import com.zhang.query.BaseQuery;
import com.zhang.query.DepartmentQuery;
import com.zhang.service.Impl.AddressServiceImpl;
import com.zhang.service.Impl.DepartmentServiceImpl;
import com.zhang.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zh
 * @create 2022-02-21 14:09
 */
@RestController
@RequestMapping("address")
public class AddressController {
    @Resource
    private AddressServiceImpl service;
    @PutMapping
    private AjaxResult addOrUpdate(@RequestBody orderAddress d){
        if(d.getId()!=null){
            try {
                service.update(d);
                return AjaxResult.me();
            } catch (Exception e) {
                e.printStackTrace();
                return AjaxResult.me(false,"修改失败");
            }
        }else {
            try {
                service.add(d);
                return AjaxResult.me();
            } catch (Exception e) {
                e.printStackTrace();
                return AjaxResult.me(false,"添加失败");
            }
        }
    }
    @DeleteMapping("/{id}")
    private AjaxResult delete(@PathVariable("id") Long id){
        try {
            service.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me(false,"删除失败");
        }
    }
    @PostMapping
    private AjaxResult getAllData(@RequestBody BaseQuery query){
        try {
            PageInfo<orderAddress> pageInfo = service.selectData(query);
            return AjaxResult.me(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me(false,"查询失败");
        }
    }

}
